package com.ruoyi.web.controller.production.seed;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.order.domain.CropType;
import com.ruoyi.order.service.ICropTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 蔬菜类型Controller
 *
 * @author ruoyi
 * @date 2021-07-08
 */
@RestController
@RequestMapping("/seed/type")
public class CropTypeController extends BaseController
{
    @Autowired
    private ICropTypeService cropTypeService;

    /**
     * 查询蔬菜类型列表
     */
    @PreAuthorize("@ss.hasPermi('seed:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(CropType cropType)
    {
        startPage();
        List<CropType> list = cropTypeService.selectCropTypeList(cropType);
        return getDataTable(list);
    }

    /**
     * 查询所有蔬菜类型
     */
    @PreAuthorize("@ss.hasPermi('seed:type:all')")
    @GetMapping("/all")
    public AjaxResult all(){
        List<CropType> cropTypes = cropTypeService.selectCropTypeList(new CropType());
        return AjaxResult.success(cropTypes);
    }

    /**
     * 导出蔬菜类型列表
     */
    @PreAuthorize("@ss.hasPermi('seed:type:export')")
    @Log(title = "蔬菜类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CropType cropType)
    {
        List<CropType> list = cropTypeService.selectCropTypeList(cropType);
        ExcelUtil<CropType> util = new ExcelUtil<CropType>(CropType.class);
        return util.exportExcel(list, "蔬菜类型数据");
    }

    /**
     * 获取蔬菜类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('seed:type:query')")
    @GetMapping(value = "/{cropTypeId}")
    public AjaxResult getInfo(@PathVariable("cropTypeId") Long cropTypeId)
    {
        return AjaxResult.success(cropTypeService.selectCropTypeById(cropTypeId));
    }

    /**
     * 新增蔬菜类型
     */
    @PreAuthorize("@ss.hasPermi('seed:type:add')")
    @Log(title = "蔬菜类型", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody CropType cropType)
    {
        return toAjax(cropTypeService.insertCropType(cropType));
    }

    /**
     * 修改蔬菜类型
     */
    @PreAuthorize("@ss.hasPermi('seed:type:edit')")
    @Log(title = "蔬菜类型", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody CropType cropType)
    {
        return toAjax(cropTypeService.updateCropType(cropType));
    }

    /**
     * 删除蔬菜类型
     */
    @PreAuthorize("@ss.hasPermi('seed:type:remove')")
    @Log(title = "蔬菜类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cropTypeIds}")
    public AjaxResult remove(@PathVariable Long[] cropTypeIds)
    {
        return toAjax(cropTypeService.deleteCropTypeByIds(cropTypeIds));
    }
}
